﻿ 
using SHKF.B2C.MeiTuanShanGou.Model.Entity;
using SqlSugar;
using System;
 
namespace SHKF.B2C.MeiTuanShanGou.BLL
{
    public class TokenMtsgBLL : CenterBLL
    {  
        public TokenMtsgBLL(SqlSugarClient db ) :
            base(db)
        {
            
        }

        public TokenMeiTuanEntity Save(TokenMeiTuanEntity token)
        { 
            TokenMeiTuanEntity info = Get(token.app_poi_code); 
            if (info == null)
            {
                db.Insertable<TokenMeiTuanEntity>(token)
                                 .ExecuteCommand();
            }
            else
            {
                token.SN = info.SN;
                db.Updateable<TokenMeiTuanEntity>(token) 
                        .ExecuteCommand();
            }
            return token;
        }

        public TokenMeiTuanEntity Get(long app_poi_code)
        { 
            TokenMeiTuanEntity token =  db.Queryable<TokenMeiTuanEntity>()
                   .Where(oo => oo.app_poi_code == app_poi_code)
                   .First();

            return token;
        }
    }

}
